package com.web.music.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.web.music.interfaces.PersistenceHelper;
import com.web.music.interfaces.PersonService;
import com.web.music.model.PersistentEntity;
import com.web.music.model.Person;

@Transactional
public class PersonServiceImpl implements PersonService {
	
	private PersistenceHelper persistence;
	
	public void save(Person person) {
		persistence.save(person);
	}

	public List<Person> findAll() {
		List<PersistentEntity> all = persistence.findAll(Person.class);
		List<Person> people = new ArrayList<Person>(); 
		for (PersistentEntity e: all){
			people.add((Person)e);
		}
		return people; 
	}
	
	public Person getById(Long id) {
		return (Person)persistence.getById(Person.class, id);
	}

	public PersistenceHelper getPersistence() {
		return persistence;
	}

	public void setPersistence(PersistenceHelper persistence) {
		this.persistence = persistence;
	}
}